broadway: Track surface position correctly
authorAlexander Larsson <alexl@redhat.com>
Fri, 13 Mar 2020 13:33:07 +0000 (14:33 +0100)
committerAlexander Larsson <alexl@redhat.com>
Fri, 13 Mar 2020 14:05:59 +0000 (15:05 +0100)
surface->x/y (and various x,y arguments) should be in the parent
coordinates, so treat it as such. We also keep track of the root coords
as these are needed for popup positioning.

Also, drop the isTemp property server side and the weird initial
placement at (100, 100) in the daemon. We now fully control window
placement from the client instead. If this is not we want we should do
a serious design for that but until then lets do the simplest thing.

13 files changed:
gdk/broadway/broadway-output.c
gdk/broadway/broadway-output.h
gdk/broadway/broadway-protocol.h
gdk/broadway/broadway-server.c
gdk/broadway/broadway-server.h
gdk/broadway/broadway.js
gdk/broadway/broadwayd.c
gdk/broadway/gdkbroadway-server.c
gdk/broadway/gdkbroadway-server.h
gdk/broadway/gdkeventsource.c
gdk/broadway/gdkprivate-broadway.h
gdk/broadway/gdksurface-broadway.c
gdk/broadway/gdksurface-broadway.h

index b2b15f83625f86a29f69bdff7f9e12b187452d41..15d76cda750eb82426ffa5208da2917115de9b0b 100644 (file)
@@ -200,8 +200,7 @@ broadway_output_ungrab_pointer (BroadwayOutput *output)
 
 void
 broadway_output_new_surface(BroadwayOutput *output,
-                            int id, int x, int y, int w, int h,
-                            gboolean is_temp)
+                            int id, int x, int y, int w, int h)
 {
   write_header (output, BROADWAY_OP_NEW_SURFACE);
   append_uint16 (output, id);
@@ -209,7 +208,6 @@ broadway_output_new_surface(BroadwayOutput *output,
   append_uint16 (output, y);
   append_uint16 (output, w);
   append_uint16 (output, h);
-  append_bool (output, is_temp);
 }
 
 void
index 036aa05c37313b64963959128f7f5935acf77dd0..58c1005727dbb90c057eb4fa1a4226a0202fa50e 100644 (file)
@@ -30,8 +30,7 @@ void            broadway_output_new_surface         (BroadwayOutput *output,
                                                      int             x,
                                                      int             y,
                                                      int             w,
-                                                     int             h,
-                                                     gboolean        is_temp);
+                                                     int             h);
 void            broadway_output_disconnected        (BroadwayOutput *output);
 void            broadway_output_show_surface        (BroadwayOutput *output,
                                                      int             id);
index 436d60da49cecb98758370aed68d6f1e2040be33..35fb02cab226a867a35192bbf13060617b6bb7c6 100644 (file)
@@ -276,7 +276,6 @@ typedef struct {
   gint32 y;
   guint32 width;
   guint32 height;
-  guint32 is_temp;
 } BroadwayRequestNewSurface;
 
 typedef struct {
index f7a380ec268033b2d640ed7b8ece876f812555f2..64f3e236de20a49f21c799813c389d9a7fb96f2f 100644 (file)
@@ -120,7 +120,6 @@ struct BroadwaySurface {
   gint32 y;
   gint32 width;
   gint32 height;
-  gboolean is_temp;
   gboolean visible;
   gint32 transient_for;
   guint32 texture;
@@ -2074,8 +2073,7 @@ broadway_server_new_surface (BroadwayServer *server,
                              int x,
                              int y,
                              int width,
-                             int height,
-                             gboolean is_temp)
+                             int height)
 {
   BroadwaySurface *surface;
 
@@ -2084,15 +2082,8 @@ broadway_server_new_surface (BroadwayServer *server,
   surface->id = server->id_counter++;
   surface->x = x;
   surface->y = y;
-  if (x == 0 && y == 0 && !is_temp)
-    {
-      /* TODO: Better way to know if we should pick default pos */
-      surface->x = 100;
-      surface->y = 100;
-    }
   surface->width = width;
   surface->height = height;
-  surface->is_temp = is_temp;
   surface->node_lookup = g_hash_table_new (g_direct_hash, g_direct_equal);
 
   g_hash_table_insert (server->surface_id_hash,
@@ -2107,8 +2098,7 @@ broadway_server_new_surface (BroadwayServer *server,
                                  surface->x,
                                  surface->y,
                                  surface->width,
-                                 surface->height,
-                                 surface->is_temp);
+                                 surface->height);
   else
     fake_configure_notify (server, surface);
 
@@ -2148,8 +2138,7 @@ broadway_server_resync_surfaces (BroadwayServer *server)
                                    surface->x,
                                    surface->y,
                                    surface->width,
-                                   surface->height,
-                                   surface->is_temp);
+                                   surface->height);
     }
 
   /* Then do everything that may reference other surfaces */
index 10181c3d795b0ad2ea47f5e1894215b786453245..7c5d97e4aa2cc41d44d3e708502f4ad619cb864a 100644 (file)
@@ -91,8 +91,7 @@ guint32             broadway_server_new_surface               (BroadwayServer  *
                                                                int              x,
                                                                int              y,
                                                                int              width,
-                                                               int              height,
-                                                               gboolean         is_temp);
+                                                               int              height);
 void                broadway_server_destroy_surface           (BroadwayServer  *server,
                                                                gint             id);
 gboolean            broadway_server_surface_show              (BroadwayServer  *server,
index da1e06fb92f6d11364a62444c32737b34e680a98..267ef205ee16ccba1fe97aa5f931af299944f544 100644 (file)
@@ -298,10 +298,9 @@ function sendConfigureNotify(surface)
     sendInput(BROADWAY_EVENT_CONFIGURE_NOTIFY, [surface.id, surface.x, surface.y, surface.width, surface.height]);
 }
 
-function cmdCreateSurface(id, x, y, width, height, isTemp)
+function cmdCreateSurface(id, x, y, width, height)
 {
-    var surface = { id: id, x: x, y:y, width: width, height: height, isTemp: isTemp };
-    surface.positioned = isTemp;
+    var surface = { id: id, x: x, y:y, width: width, height: height };
     surface.transientParent = 0;
     surface.visible = false;
     surface.imageData = null;
@@ -1039,8 +1038,7 @@ function handleCommands(cmd, display_commands, new_textures, modified_trees)
             y = cmd.get_16s();
             w = cmd.get_16();
             h = cmd.get_16();
-            var isTemp = cmd.get_bool();
-            var div = cmdCreateSurface(id, x, y, w, h, isTemp);
+            var div = cmdCreateSurface(id, x, y, w, h);
             display_commands.push([DISPLAY_OP_APPEND_ROOT, div]);
             need_restack = true;
             break;
@@ -1109,7 +1107,6 @@ function handleCommands(cmd, display_commands, new_textures, modified_trees)
             var has_size = ops & 2;
             surface = surfaces[id];
             if (has_pos) {
-                surface.positioned = true;
                 surface.x = cmd.get_16s();
                 surface.y = cmd.get_16s();
                 display_commands.push([DISPLAY_OP_MOVE_NODE, surface.div, surface.x, surface.y]);
index d65e69c4ceef978dbda47e448d6a8dde143b56f8..a7a759c2add2b8325bad9897555c985ab32ef280 100644 (file)
@@ -238,8 +238,7 @@ client_handle_request (BroadwayClient *client,
                                      request->new_surface.x,
                                      request->new_surface.y,
                                      request->new_surface.width,
-                                     request->new_surface.height,
-                                     request->new_surface.is_temp);
+                                     request->new_surface.height);
       client->surfaces =
         g_list_prepend (client->surfaces,
                         GUINT_TO_POINTER (reply_new_surface.id));
index 4b8fe4fd9b03e4055dbcecc50d0bbe63f499453d..23207916dbbf6eec25e1c6bce1d248054ccdf5b7 100644 (file)
@@ -482,8 +482,7 @@ _gdk_broadway_server_new_surface (GdkBroadwayServer *server,
                                  int x,
                                  int y,
                                  int width,
-                                 int height,
-                                 gboolean is_temp)
+                                 int height)
 {
   BroadwayRequestNewSurface msg;
   guint32 serial, id;
@@ -493,7 +492,6 @@ _gdk_broadway_server_new_surface (GdkBroadwayServer *server,
   msg.y = y;
   msg.width = width;
   msg.height = height;
-  msg.is_temp = is_temp;
   serial = gdk_broadway_server_send_message (server, msg,
                                              BROADWAY_REQUEST_NEW_SURFACE);
   reply = gdk_broadway_server_wait_for_reply (server, serial);
index b30e38a5a6b90dedf398e34a7b82327a14ed025c..f399ff458cc255fe729de06a0e677272ce861ae8 100644 (file)
@@ -43,8 +43,7 @@ guint32            _gdk_broadway_server_new_surface               (GdkBroadwaySe
                                                                  int                 x,
                                                                  int                 y,
                                                                  int                 width,
-                                                                 int                 height,
-                                                                 gboolean            is_temp);
+                                                                 int                 height);
 void               _gdk_broadway_server_destroy_surface           (GdkBroadwayServer  *server,
                                                                  gint                id);
 gboolean           _gdk_broadway_server_surface_show              (GdkBroadwayServer  *server,
index 9e8f56296ce12d377526746af7e70a9c0e952805..0f83b8b6f6803836f91c0ab52fb1cf4f6bc7e1fe 100644 (file)
@@ -294,11 +294,6 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
     surface = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (message->configure_notify.id));
     if (surface)
       {
-        surface->x = message->configure_notify.x;
-        surface->y = message->configure_notify.y;
-
-        gdk_broadway_surface_update_popups (surface);
-
         event = gdk_event_configure_new (surface,
                                          message->configure_notify.width,
                                          message->configure_notify.height);
index f4f19cd534c2e6e9e95948706b41af1f4268fdf6..5a4499b4085bfe6cf71fdb5925a5dd0ac57cd6a1 100644 (file)
@@ -67,7 +67,6 @@ void     _gdk_broadway_roundtrip_notify           (GdkSurface  *surface,
 void     _gdk_broadway_surface_grab_check_destroy (GdkSurface *surface);
 void     _gdk_broadway_surface_grab_check_unmap   (GdkSurface *surface,
                                                    gulong     serial);
-void     gdk_broadway_surface_update_popups       (GdkSurface *surface);
 
 void gdk_broadway_surface_move_resize (GdkSurface *surface,
                                        gint        x,
index 0193f499b2e0acf2a3ad32f080301235da865e2a..bb3acf2f985d3e88ed2d648d0c5247a8831b89ad 100644 (file)
@@ -253,12 +253,19 @@ _gdk_broadway_display_create_surface (GdkDisplay     *display,
   broadway_display = GDK_BROADWAY_DISPLAY (display);
 
   impl = GDK_BROADWAY_SURFACE (surface);
+  impl->root_x = x;
+  impl->root_y = y;
+  if (parent)
+    {
+      impl->root_x += GDK_BROADWAY_SURFACE (parent)->root_x;
+      impl->root_y += GDK_BROADWAY_SURFACE (parent)->root_y;
+    }
+
   impl->id = _gdk_broadway_server_new_surface (broadway_display->server,
-                                               surface->x,
-                                               surface->y,
+                                               impl->root_x,
+                                               impl->root_y,
                                                surface->width,
-                                               surface->height,
-                                               surface_type == GDK_SURFACE_TEMP);
+                                               surface->height);
   g_hash_table_insert (broadway_display->id_ht, GINT_TO_POINTER(impl->id), surface);
 
   if (!surface->parent)
@@ -399,6 +406,41 @@ gdk_broadway_surface_get_scale_factor (GdkSurface *surface)
   return broadway_display->scale_factor;
 }
 
+static void
+sync_child_root_pos (GdkSurface *parent)
+{
+  GdkBroadwaySurface *parent_impl = GDK_BROADWAY_SURFACE (parent);
+  GdkBroadwayDisplay *broadway_display;
+  GList *l;
+
+  broadway_display = GDK_BROADWAY_DISPLAY (gdk_surface_get_display (parent));
+
+  for (l = parent->children; l; l = l->next)
+    {
+      GdkBroadwaySurface *child_impl = l->data;
+      GdkSurface *child = GDK_SURFACE (child_impl);
+      int root_x, root_y;
+
+      root_x = child->x + parent_impl->root_x;
+      root_y = child->y + parent_impl->root_y;
+
+      if (root_x != child_impl->root_x ||
+          root_y != child_impl->root_y)
+        {
+          child_impl->root_x = root_x;
+          child_impl->root_y = root_y;
+
+          _gdk_broadway_server_surface_move_resize (broadway_display->server,
+                                                    child_impl->id,
+                                                    TRUE,
+                                                    child_impl->root_x, child_impl->root_y,
+                                                    child->width, child->height);
+          sync_child_root_pos (child);
+        }
+    }
+}
+
+/* x, y is relative to parent */
 static void
 gdk_broadway_surface_move_resize_internal (GdkSurface *surface,
                                            gboolean    with_move,
@@ -411,6 +453,20 @@ gdk_broadway_surface_move_resize_internal (GdkSurface *surface,
   GdkBroadwayDisplay *broadway_display;
   gboolean size_changed;
 
+  if (with_move)
+    {
+      surface->x = x;
+      surface->y = y;
+      impl->root_x = x;
+      impl->root_y = y;
+      if (surface->parent)
+        {
+          GdkBroadwaySurface *parent_impl = GDK_BROADWAY_SURFACE (surface->parent);
+          impl->root_x += parent_impl->root_x;
+          impl->root_y += parent_impl->root_y;
+        }
+    }
+
   size_changed = FALSE;
 
   broadway_display = GDK_BROADWAY_DISPLAY (gdk_surface_get_display (surface));
@@ -437,17 +493,13 @@ gdk_broadway_surface_move_resize_internal (GdkSurface *surface,
         }
     }
 
-  if (surface->parent)
-    {
-      impl->offset_x = x - surface->parent->x;
-      impl->offset_y = y - surface->parent->y;
-    }
-
   _gdk_broadway_server_surface_move_resize (broadway_display->server,
                                             impl->id,
                                             with_move,
-                                            x, y,
+                                            impl->root_x, impl->root_y,
                                             surface->width, surface->height);
+  sync_child_root_pos (surface);
+
   queue_flush (surface);
   if (size_changed)
     {
@@ -501,9 +553,8 @@ gdk_broadway_surface_layout_popup (GdkSurface     *surface,
                                    layout,
                                    &final_rect);
 
-  gdk_surface_get_origin (surface->parent, &x, &y);
-  x += final_rect.x;
-  y += final_rect.y;
+  x = final_rect.x;
+  y = final_rect.y;
 
   if (final_rect.width != surface->width ||
       final_rect.height != surface->height)
@@ -658,10 +709,14 @@ gdk_broadway_surface_get_root_coords (GdkSurface *surface,
                                       gint       *root_x,
                                       gint       *root_y)
 {
+  GdkBroadwaySurface *impl;
+
+  impl = GDK_BROADWAY_SURFACE (surface);
+
   if (root_x)
-    *root_x = x + surface->x;
+    *root_x = x + impl->root_x;
   if (root_y)
-    *root_y = y + surface->y;
+    *root_y = y + impl->root_y;
 }
 
 static gboolean
@@ -762,25 +817,6 @@ gdk_broadway_surface_unmaximize (GdkSurface *surface)
                                     impl->pre_maximize_height);
 }
 
-void
-gdk_broadway_surface_update_popups (GdkSurface *parent)
-{
-  GList *l;
-
-  for (l = parent ->children; l; l = l->next)
-    {
-      GdkBroadwaySurface *popup_impl = l->data;
-      GdkSurface *popup = GDK_SURFACE (popup_impl);
-      int new_x = parent->x + popup_impl->offset_x;
-      int new_y = parent->y + popup_impl->offset_y;
-
-      if (new_x != popup->x || new_y != popup->y)
-        gdk_broadway_surface_move_resize (popup,
-                                          new_x, new_y,
-                                          popup->width, popup->height);
-    }
-}
-
 typedef struct _MoveResizeData MoveResizeData;
 
 struct _MoveResizeData
index b2940f2b08143de9aedd8961a5473ebd91f2fcbd..33ef70eb038119eb0bfc355b087c68ff2c5099cb 100644 (file)
@@ -61,8 +61,8 @@ struct _GdkBroadwaySurface
   GArray *node_data;
   GPtrArray *node_data_textures;
 
-  int offset_x;
-  int offset_y;
+  int root_x;
+  int root_y;
 };
 
 struct _GdkBroadwaySurfaceClass